package com.github.xiaolyuh;

import com.github.xiaolyuh.base.BasicCacheManager;
import com.github.xiaolyuh.configcenter.ConfigCenter;
import com.github.xiaolyuh.dataloader.DataLoader;
import com.github.xiaolyuh.entity.CacheKey;
import com.github.xiaolyuh.entity.CacheValue;
import com.github.xiaolyuh.exception.CacheException;
import com.github.xiaolyuh.manager.impl.CacheManagerImpl;
import org.springframework.stereotype.Component;

/**
 * 本地缓存
 *
 * @author xuwanglong
 */
@Component
public class LocalCacheOnlyManager extends CacheManagerImpl {

    public <T, K> T get(CacheKey<K> cacheKey, Class<T> clazz, DataLoader<K, T> dataLoader, BasicCacheManager localCacheManager) throws CacheException {
        return super.get(cacheKey, clazz, dataLoader, null, localCacheManager);
    }

    public <T, K> void refresh(CacheKey<K> cacheKey, Class<T> clazz, DataLoader<K, T> dataLoader, boolean async, BasicCacheManager localCacheManager) throws CacheException {
        super.refresh(cacheKey, clazz, dataLoader, async, null, localCacheManager);
    }

    public boolean delete(String key, BasicCacheManager distributeCacheManager, BasicCacheManager localCacheManager) throws CacheException {
        return super.delete(key, null, localCacheManager);
    }

    public <K, T> void set(CacheKey<K> cacheKey, CacheValue<T> cacheValue, BasicCacheManager localCacheManager) throws CacheException {
        super.set(cacheKey, cacheValue, null, localCacheManager);
    }

    public <K, T> void setWithFake(CacheKey<K> cacheKey, CacheValue<T> cacheValue, BasicCacheManager localCacheManager) throws CacheException {
        super.setWithFake(cacheKey, cacheValue, null, localCacheManager);
    }

    @Override
    public Boolean isDistributeEnable() {
        return Boolean.FALSE;
    }

    @Override
    public Boolean isLocalCacheEnable() {
        return ConfigCenter.allowLocalCache();
    }

}
